﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;

public partial class OrderManage : System.Web.UI.Page
{
    private static IList<OrderInfo> undealList;
    private static IList<OrderInfo> dealedList;
    private static IList<OrderInfo> deletedList;
    private static Order order = new Order();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            undealList = order.GetUnDealedOrders();
            dealedList = order.GetDealedOrders();
            deletedList = order.GetCanceledOrders();
            UndealOrder.DataSource = undealList;
            DealOrder.DataSource = dealedList;
            DeletedItem.DataSource = deletedList;
            DealOrder.DataBind();
            UndealOrder.DataBind();
            DeletedItem.DataBind();
        }
    }

    protected void UndealOrder_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        if (e.CommandName == "Delete")
        {
            try
            {
                order.CancelOrder(undealList[e.Item.ItemIndex].OrderId);
                Response.Write("<script>alert('删除订单成功')</script>");
                undealList = order.GetUnDealedOrders();
                dealedList = order.GetDealedOrders();
                deletedList = order.GetCanceledOrders();
                UndealOrder.DataSource = undealList;
                DealOrder.DataSource = dealedList;
                DeletedItem.DataSource = deletedList;
                DealOrder.DataBind();
                UndealOrder.DataBind();
                DeletedItem.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("<script>alert('删除订单失败: " + ex.Message + "')</script>");
            }

        }

        if (e.CommandName == "Deal")
        {
            try
            {
                order.DealOrder(undealList[e.Item.ItemIndex].OrderId);
                Response.Write("<script>alert('处理订单成功')</script>");
                undealList = order.GetUnDealedOrders();
                dealedList = order.GetDealedOrders();
                deletedList = order.GetCanceledOrders();
                UndealOrder.DataSource = undealList;
                DealOrder.DataSource = dealedList;
                DeletedItem.DataSource = deletedList;
                DealOrder.DataBind();
                UndealOrder.DataBind();
                DeletedItem.DataBind();
            }
            catch (Exception ex)
            {
                Response.Write("失败");
                Response.Write("<script>alert('处理订单失败: " + ex.Message + "')</script>");
            }
        }
    }
}
